﻿#region License

// This file is part of Grawlix.
// 
// Grawlix is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
// Grawlix is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public
// License along with Grawlix.  If not, see
// <http://www.gnu.org/licenses/>.

#endregion

/*using System;
using System.Configuration;
using System.Globalization;
using System.Reflection;
using Castle.Core.Configuration;
using Castle.Windsor;
using Castle.Windsor.Installer;

namespace Grawlix.Services
{
	/// <summary>
	/// An installer for <see cref="WindsorContainer"/> that puts
	/// code in a new <see cref="AppDomain"/>.
	/// </summary>
	public class AddInComponentInstaller :
		DefaultComponentInstaller
	{
		/// <summary>
		/// Locates a type with the specified name.
		/// </summary>
		/// <param name="typeName">The name of the type to locate.
		/// </param>
		/// <returns>The type specified.</returns>
		/// <exception cref="ConfigurationErrorsException">
		/// <paramref name="typeName"/> could not be located.
		/// </exception>
		protected static Type ObtainType(string typeName)
		{
			Type type = Type.GetType(typeName, false, false);
			if (type == null)
			{
				throw new ConfigurationErrorsException(
					string.Format(CultureInfo.InvariantCulture,
					              "The type name {0} could not be located",
					              typeName));
			}
			return type;
		}

		/// <summary>
		/// Locates a type and creates a proxy to it, if feasible.
		/// </summary>
		/// <param name="typeName">
		/// The name of the type to proxy then load.
		/// </param>
		/// <param name="serviceType">
		/// The interface type to implement.
		/// </param>
		/// <returns>The proxied type, or the original if available.
		/// </returns>
		/// <exception cref="ConfigurationErrorsException">
		/// <paramref name="typeName"/> could not be located.
		/// </exception>
		protected static Type ObtainTypeProxy(string typeName,
		                                      Type serviceType)
		{
			// TODO: Load types in separate AppDomain.
			// TODO: Create and return proxy.
			return ObtainType(typeName);
		}

		/// <summary>
		/// Installs services without injecting their types into the
		/// main <see cref="Assembly"/>, if not already loaded.
		/// </summary>
		/// <param name="configurations">
		/// The configuration for each component.
		/// </param>
		/// <param name="container">The container to configure.</param>
		protected override void SetUpComponents(
			IConfiguration[] configurations,
			IWindsorContainer container)
		{
			foreach (var configuration in configurations)
			{
				string key = configuration.Attributes["id"];
				string typeName = configuration.Attributes["type"];
				string str3 = configuration.Attributes["service"];
				if (!string.IsNullOrEmpty(typeName))
				{
					Type serviceType;
					Type classType;
					if (!string.IsNullOrEmpty(str3))
					{
						serviceType = ObtainType(str3);
						classType = ObtainTypeProxy(typeName, serviceType);
					}
					else
					{
						classType = ObtainType(typeName);
						serviceType = classType;
					}
					container.AddComponent(key, serviceType, classType);
				}
			}
		}
	}
}*/